<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>网站模块-商品信息</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" /></head>
<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox" id="tool">
		<div class="layui-inline">
			<label class="layui-input-inline">商品名称</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="name" placeholder="请输入商品名称" /></label>
			<label class="layui-input-inline">所属栏目</label>
			<label class="layui-input-inline">
				<select name="colId" id="colId"></select>
			</label>
			<label class="layui-input-inline">标签名称</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="tagNames" placeholder="请输入标签名称" /></label>
			<label class="layui-input-inline">是否展示</label>
			<label class="layui-input-inline">
				<select name="showType" id="showType"></select>
			</label>
			<a class="layui-btn search_btn" lay-submit="" lay-filter="seacherBtn">搜索</a><a class="layui-btn layui-btn-normal addBtn" data-title="添加" data-url="/webProduct/getEntity">添加</a></div>
	</blockquote>
	<table id="entityList" lay-filter="entityList"></table>
</form>
<script type="text/html" id="entityBar">
	<a class = "layui-btn cy-btnbg-edit layui-btn-sm" lay-event="edit"> 编辑 </a>
	<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a >
</script>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">layui.use(['jquery', 'pageUtil', 'table', 'dateUtil', 'fileUtil'],
    function() {
        var $ = layui.jquery,
            dateUtil = layui.dateUtil,
            table = layui.table,
            fileUtil = layui.fileUtil,
            pageUtil = layui.pageUtil;
        var tableIns = null;
        pageUtil.initDictByUrl("/webColumnType/acceptSelect?colType=3","web_col_name",
            function(dictDataUrl) {
                pageUtil.initDict("base_show_type,base_unit_name",
                    function(dictData) {
                        pageUtil.showDict($("#colId"), pageUtil.aceeptDictContentList(dictDataUrl, "web_col_name"), "请选择所属栏目");
                        pageUtil.showDict($("#showType"), pageUtil.aceeptDictContentList(dictData, "base_show_type"), "请选择是否展示");
                        var url = "/webProduct/page";
                        var cols = [{
                            type: 'checkbox',
                            fixed: 'left'
                        },
                            {
                                type: 'numbers',
                                title: '序号'
                            },
                            {
                                field: 'name',
                                title: '商品名称',
                                align: 'center'
                            },
                            {
                                field: 'colId',
                                title: '所属栏目',
                                width: 250,
                                align: 'center',
                                templet: function(d) {
                                    return pageUtil.aceeptDictContentName(dictDataUrl, 'web_col_name', d.colId);
                                }
                            },
                            {
                                field: 'origPrice',
                                title: '原价',
                                align: 'center'
                            },
                            {
                                field: 'persentPrice',
                                title: '现价',
                                align: 'center'
                            },
                            {
                                field: 'tagNames',
                                title: '标签名称',
                                align: 'center'
                            },
                            {
                                field: 'images',
                                title: '商品图',
                                align: 'center',
                                templet: function(d) {
                                    return "<img lay-event ='showPicture' src='"+d.images+"' style='width:auto; max-width: 96%; height: 44px;'/>";
                                }
                            },
                            {
                                field: 'coverImage',
                                title: '封面图',
                                align: 'center',
                                templet: function(d) {
                                    return "<img lay-event ='showImagePicture' src='"+d.coverImage+"' style='width:auto; max-width: 96%; height: 44px;'/>";
                                }
                            },
                            {
                                field: 'saleNum',
                                title: '已售数量',
                                align: 'center',
                                templet: function(d) {
                                    return d.saleNum+pageUtil.aceeptDictContentName(dictData, 'base_unit_name', d.unitName);
                                }
                            },
                            {
                                field: 'showType',
                                title: '是否展示',
                                align: 'center',
                                templet: function(d) {
                                    return pageUtil.aceeptDictContentName(dictData, 'base_show_type', d.showType);
                                }
                            },
                            {
                                field: 'createTime',
                                title: '创建时间',
                                width: 190,
                                align: 'center',
                                templet: function(d) {
                                    return dateUtil.formatDate(new Date(d.createTime), "yyyy-MM-dd hh:mm:ss");
                                }
                            },
                            {
                                title: '操作',
                                width: 150,
                                templet: '#entityBar',
                                align: "center",
                                fixed: 'right'
                            }];
                        tableIns = pageUtil.initDate(cols, url, true);
                    });
            });

        table.on('tool(entityList)',
            function(obj) {
                var layEvent = obj.event,
                    data = obj.data;
                if (layEvent === 'edit') {
                    pageUtil.editPopup("编辑", "/webProduct/getEntity?id=" + data.id);
                } else if (layEvent === 'showImagePicture') {
                    fileUtil.imageSingleShow(data.coverImage);
                } else if (layEvent === 'showPicture') {
                    fileUtil.imageSingleShow(data.images);
                } else if (layEvent === 'del') {
                    pageUtil.delete("确定删除该项吗？", "/webProduct/delete", {
                            "id": data.id,
                            "_method": "DELETE"
                        },
                        function(data) {
                            tableIns.reload();
                        });
                }
            });
    })</script>
</body>

</html>